//
//  ChartsVC.m
//  WanCaiC8
//
//  Created by tangang on 2017/12/29.
//  Copyright © 2017年 tangang. All rights reserved.
//

#import "ChartsVC.h"
#import "MovementsModel.h"
#import "LotteryTypeView.h"
#import "MovementsCell.h"
#import "MovementsContentCell.h"
@interface ChartsVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,strong) LotteryTypeView *lotteryTypeView;
@property (nonatomic ,strong) UITableView *tableView;
@property (nonatomic ,strong) NSMutableArray *dataArr;
@end

@implementation ChartsVC{
    NSInteger   selectType;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem=nil;
    self.title=@"走势";
    // Do any additional setup after loading the view.
    [self.tableView reloadData];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.hidesBottomBarWhenPushed = NO;
    self.tabBarController.tabBar.hidden = NO;

}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

#pragma mark -- UITableViewDelegate ,UITableViewDataSource
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    if (indexPath.row==0) {
        return 60;
    }
    return 130;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArr.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    MovementsModel *model=self.dataArr[section];
    if (model.isOpen) {
        return 2;
    }
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        MovementsCell *cell=[tableView dequeueReusableCellWithIdentifier:@"MovementsCell" forIndexPath:indexPath];
        [cell setModel:self.dataArr[indexPath.section]];
        return cell;
    }else{
        MovementsContentCell *cell=[tableView dequeueReusableCellWithIdentifier:@"MovementsContentCell" forIndexPath:indexPath];
        [cell setModel:self.dataArr[indexPath.section]];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MovementsModel *model=self.dataArr[indexPath.section];
    model.isOpen=!model.isOpen;
    [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
}

#pragma mark -- 懒加载
- (UITableView *)tableView{
    if (!_tableView) {
        WS(weakSelf);
        _tableView=[[UITableView alloc]init];
        _tableView.dataSource=self;
        _tableView.delegate=self;
        _tableView.backgroundColor=DEFAULTBGCOLOR;
        [_tableView registerClass:[MovementsCell class] forCellReuseIdentifier:@"MovementsCell"];
        [_tableView registerClass:[MovementsContentCell class] forCellReuseIdentifier:@"MovementsContentCell"];
        _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(weakSelf.view);
            make.top.equalTo(weakSelf.lotteryTypeView.mas_bottom)
            .with.offset(5);
        }];
    }
    return _tableView;
}

- (LotteryTypeView *)lotteryTypeView{
    if (!_lotteryTypeView) {
        WS(weakSelf);
        _lotteryTypeView=[[LotteryTypeView alloc]init];
        _lotteryTypeView.chaneBlock = ^(NSInteger row) {
            selectType=row;
        };
        [self.view addSubview:_lotteryTypeView];
        [_lotteryTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.equalTo(weakSelf.view);
            make.height.mas_equalTo(@40);
        }];
    }
    return _lotteryTypeView;
}


- (NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr=[[NSMutableArray alloc]init];
        [_dataArr addObject:[[MovementsModel alloc]init]];
        [_dataArr addObject:[[MovementsModel alloc]init]];
        [_dataArr addObject:[[MovementsModel alloc]init]];
        [_dataArr addObject:[[MovementsModel alloc]init]];
        [_dataArr addObject:[[MovementsModel alloc]init]];
        [_dataArr addObject:[[MovementsModel alloc]init]];
    }
    return _dataArr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
